from Common.Singleton import Singleton 
from Config.DBConnConfig import *
import cx_Oracle
#import os
#import MySQLdb

class DBConnFactory(Singleton):
	#def init_only_once(self):    #aas an substitute of __init__(self)
	#	print "info, connecting db..."
	#	self.db_conn = cx_Oracle.connect('rs','rs','192.168.142.83:1521/van')
		
	def get_db_connection(self, db_name):
		if db_name=='FINCHINA':
		
			if not hasattr(self, "finch_db_conn"):
				setattr(self, "finch_db_conn", None)
				
			if not self.finch_db_conn:			
				self.finch_db_conn = cx_Oracle.connect(FINCHINA_DB_CONN_PARAM[2],
													FINCHINA_DB_CONN_PARAM[3],
													FINCHINA_DB_CONN_PARAM[1])
				#print "info, db connection complete. "  #, self.finch_db_conn.dsn
			
			return self.finch_db_conn
			
		elif db_name=='FINCHINAHF':
		
			if not hasattr(self, "finchhf_db_conn"):
				setattr(self, "finchhf_db_conn", None)
				
			if not self.finchhf_db_conn:			
				self.finchhf_db_conn = cx_Oracle.connect(FINCHINAHF_DB_CONN_PARAM[2],
													FINCHINAHF_DB_CONN_PARAM[3],
													FINCHINAHF_DB_CONN_PARAM[1])
				#print "info, db connection complete. "  #, self.finch_db_conn.dsn
			
			return self.finchhf_db_conn
			
		else:
			print 'warn, to be implemented.'
			return None

		#os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
	
	